// <copyright file="CavernGenerator.UniqueMethods.cs" company="TenneySoftware">
// Copyright (c) 2009 All Right Reserved
// </copyright>
// <author>Robert Tenney</author>
// <email>rob10e@yahoo.com</email>
// <date>April 2009</date>
// <summary>Cavern style level generator module.</summary>

// License:

// Product: RPGRoguelikeEngine .Net
// Author: Robert N. Tenney
// Copyright: April 2009

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation version 2
// of the License.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

// This license covers all source code, binaries, and other materials related to this project
// unless specifically stated otherwise.

using System;
using System.Drawing;

namespace TenneySoftware.LevelGenerator.CavernGenerator {
    /// <content>
    /// This file contains the Unque (Not defined within ILevelGenerator interface) methods for the generator.
    /// </content>
    public partial class Cavern {
        /// <summary>
        /// Adds a point of connection to the cavern. The location given must be on a point just
        /// outside of the cavern.
        /// </summary>
        /// <param name="locationX">Point of connection's X axis.</param>
        /// <param name="locationY">Point of connection's Y axis.</param>
        public void AddPassageOut(int locationX, int locationY) {
            this.AddPassageOut(new Point(locationX, locationY));
        }

        /// <summary>
        /// Adds a point of connection to the cavern. The location given must be on a point just
        /// outside of the cavern.
        /// </summary>
        /// <param name="location">Point of connection.</param>
        public void AddPassageOut(Point location) {
            if (location.X == -1 || location.X == this.Bounds.Right || location.Y == -1 || location.Y == this.Bounds.Bottom) {
                if (!this.passageOut.Contains(location)) {
                    PassageOutSeed values = new PassageOutSeed(PassageOutSeed.Shift(location, this.Level.Size));
                    if (this.Level.IsLocationWithinBounds(values.Top)) {
                        this.passageOut.Add(values.Top);
                    }

                    if (this.Level.IsLocationWithinBounds(values.Center)) {
                        this.passageOut.Add(values.Center);
                    }

                    if (this.Level.IsLocationWithinBounds(values.Bottom)) {
                        this.passageOut.Add(values.Bottom);
                    }

                    if (this.Level.IsLocationWithinBounds(values.Left)) {
                        this.passageOut.Add(values.Left);
                    }

                    if (this.Level.IsLocationWithinBounds(values.Right)) {
                        this.passageOut.Add(values.Right);
                    }
                }
            }
        }

        /// <summary>
        /// Retrieves a list of methods that are unique to this generator and not to any other.
        /// </summary>
        /// <returns>An array of GeneratorData objects with information about the unique methods within this generator.</returns>
        public GeneratorData[] GetUniqueMethodInformation() {
            GeneratorData[] result = new GeneratorData[1];
            result[0] = new GeneratorData(
                0,
                "AddPassageOut",
                "Sets a point connected to the level that will force the generator to seed a passage to.",
            new string[] { typeof(Point).ToString() });
            return result;
        }

        /// <summary>
        /// Passes parameters to unique methods within this generator through the ILevelSettings interface. Methods available are:
        /// 0 - AddPassageOut(Point location)
        /// methodCalls usage: new object[][]{new object[]{0, new Point(10, 10)}}
        /// Will call AddPassageOut with the location of 10, 10.
        /// </summary>
        /// <param name="methodCalls">Jagged array of objects with the method code at the first position, and the arguments
        /// to pass in the remaining position.</param>
        public void UseUniqueMethods(object[][] methodCalls) {
            if (methodCalls.GetLength(0) > 1) {
                throw new ArgumentException("Too many options in array. Recheck your options.");
            }
            
            foreach (object[] arg in methodCalls) {
                switch ((int)arg[0]) {
                    case 0:
                        if (arg[1] is Point) {
                            this.AddPassageOut((Point)arg[1]);
                        } else {
                            throw new ArgumentException("Must pass " + typeof(Point).ToString() +
                                                        " as the argument to use AddPassageOut(Point)");
                        }
                        
                        break;
                }
            }
        }
    }
}